package kr.saeildamil.androidstudy.ch11;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

public class TextChange extends Activity {
	EditText et;
	TextView tv;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_textchange);
		et = (EditText) findViewById(R.id.ch11_textchange_edit);
		tv = (TextView) findViewById(R.id.ch11_textchange_textview);
		
		et.setFilters(new InputFilter[] {
				new InputFilter.LengthFilter(10)
		});
		et.addTextChangedListener(watcher);
	}

	TextWatcher watcher = new TextWatcher() {
		public void onTextChanged(CharSequence s, int start, int before, int count) {
			int etsize = et.getText().toString().length();
			tv.setText("글자 수  : " + etsize + " bytes");
		}
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
		public void afterTextChanged(Editable s) {}
	};
}
